#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// heap 堆内存，可以用于申请大内存空间，需要手动申请于释放
// malloc 申请 是以字节为单位进行申请
// free 释放
int main1()
{
    char * p = (char *)malloc(1024*1024*1024);
    if(p == NULL)
        printf("malloc error\n");
    strcpy(p,"abcd");
    printf("Hello World!\n");
    free(p);
    return 0;
}

void func()
{
    printf("in func:\n");
    char *pa,*pb,*pc,*pd;
    pa = malloc(100);
    pb = malloc(100);
    pc = malloc(100);
    pd = malloc(100);

    printf("%p\n",pa);
    printf("%p\n",pb);
    printf("%p\n",pc);
    printf("%p\n",pd);
}

int main()
{
    printf("in main:\n");
    char *pa,*pb,*pc,*pd;
    pa = malloc(100);
    pb = malloc(100);
    pc = malloc(100);
    pd = malloc(100);

    printf("%p\n",pa);
    printf("%p\n",pb);
    printf("%p\n",pc);
    printf("%p\n",pd);
    func();
}
